import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import Icon from '@/components/Icon/Icon.vue';
import {getAdminMenusOptions} from "@/api/common";

export const columns = [
  {
    title: '菜单名称',
    dataIndex: 'title',
    width: 200,
    align: 'left',
  },
  {
    title: '图标',
    dataIndex: 'icon',
    width: 50,
    customRender: ({ record }) => {
      return h(Icon, { icon: record.icon });
    },
  },
  {
    title: '跳转地址',
    dataIndex: 'route',
    width: 180,
  },
  {
    title: '排序',
    dataIndex: 'sort',
  },
  {
    title: '创建时间',
    dataIndex: 'create_time',
    width: 180,
  },
];

const isDir = (type: string) => type === '0';
const isMenu = (type: string) => type === '1';
const isButton = (type: string) => type === '2';

export const searchFormSchema: FormSchema[] = [
  {
    field: 'menuName',
    label: '菜单名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '启用', value: '0' },
        { label: '停用', value: '1' },
      ],
    },
    colProps: { span: 8 },
  },
];

export const formSchema = [
  {
    field: 'title',
    label: '菜单名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'pid',
    label: '上级菜单',
    component: 'ApiTreeSelect',
    defaultValue: null,
    componentProps: {
      api: getAdminMenusOptions,
      params: { type: 'all' },
      resultField: 'result.list',
      labelField: 'title',
      valueField: 'id',
    },
  },
  {
    field: 'icon',
    label: '图标',
    component: 'IconPicker',
    required: false,
  },
  {
    field: 'route',
    label: '路由地址',
    component: 'Input',
    required: true,
  },
  {
    field: 'redirect',
    label: '跳转地址',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      const { pid = 0 } = model
      return 0 == pid;
    },
  },
  {
    field: 'component_name',
    label: '组件名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'component',
    label: '组件路径',
    component: 'Input',
    required: true,
    ifShow: ({ model }) => {
      const { pid = 0 } = model
      return 0 !== pid;
    },
  },
  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    defaultValue: 0,
    required: true,
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 'enable',
    componentProps: {
      options: [
        { label: '正常', value: 'enable' },
        { label: '禁用', value: 'disable' },
      ]
    }
  },
];
